package com.zengjianjun.storm.demo;

import com.zengjianjun.storm.demo.util.SpringContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @author zengjianjun
 */
@Slf4j
@SpringBootApplication
@Import(SpringContext.class)
public class StormDemoApplication implements CommandLineRunner {

    @Value("${storm.local:false}")
    private boolean stormLocal;

    private final static AtomicBoolean START_FLAG = new AtomicBoolean(false);

    public synchronized static void start(String... args) {
        main(args);
    }
    public static void main(String[] args) {
        if (START_FLAG.compareAndSet(false, true)) {
            SpringApplication.run(StormDemoApplication.class, args);
        }
    }

    @Override
    public void run(String... args) throws Exception {
        if (stormLocal) {
            WordCountStorm.localStart();
        }
    }
}
